package com.hd.persistence.dao;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.hd.common.DataPage;
import com.hd.common.HibernateEntityDao;
import com.hd.persistence.model.AcceptTreatmentCase;

public class AcceptTreatmentCaseDao extends HibernateEntityDao<AcceptTreatmentCase> {

	public DataPage<AcceptTreatmentCase> pageQueryAcceptTreatmentCases(String unitName, String acceptTreatmenter, Date acceptTreatmentTime, int pageNo, int pageSize) {
		StringBuilder hql = new StringBuilder("from AcceptTreatmentCase where (1=1) ");
		List<Object> objs = new ArrayList<Object>();
		if ( StringUtils.isNotBlank(unitName) ) {
			hql.append("and unitName=? ");
			objs.add(unitName);
		}
		if ( StringUtils.isNotBlank(acceptTreatmenter) ) {
			hql.append("and acceptTreatmenter=? ");
			objs.add(acceptTreatmenter);
		}
		if ( acceptTreatmentTime != null ) {
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(acceptTreatmentTime);
			long beginDate = calendar.getTimeInMillis();
			calendar.set(Calendar.HOUR_OF_DAY, 23);
			calendar.set(Calendar.MINUTE, 59);
			calendar.set(Calendar.SECOND, 59);
			calendar.set(Calendar.MILLISECOND, 999);
			long endDate = calendar.getTimeInMillis();
			hql.append("and acceptTreatmentTime>=? and acceptTreatmentTime<=? ");
			objs.add(beginDate);
			objs.add(endDate);
		}
		return pagedQuery(hql.toString(), pageNo, pageSize, "acceptTreatmentTime", false, objs.toArray());
	}
}
